package com.sdhs.workflow.utils;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.sdhs.common.utils.AESUtils;
import com.sdhs.workflow.domain.UnifyPushLog;
import com.sdhs.workflow.domain.vo.*;
import com.sdhs.workflow.service.*;
import org.springframework.beans.factory.annotation.Value;
import lombok.extern.slf4j.Slf4j;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import javax.annotation.PostConstruct;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 统一代办、统一消息集成工具类
 */
@Slf4j
@Component
public class UnifyApiUtils {

    @Autowired
    IUnifyPushApiService iUnifyPushApiService;

    @Autowired
    IUnifySetDoneApiService iUnifySetDoneApiService;

    @Autowired
    IUnifyDeleteApiService iUnifyDeleteApiService;

    @Autowired
    IUnifySendMsgApiService iUnifySendMsgApiService;

    @Autowired
    IUnifyPushLogService iUnifyPushLogService;


    private static UnifyApiUtils unifyApiUtils;

    @PostConstruct
    public void init()
    {
        unifyApiUtils = this;
        unifyApiUtils.iUnifyPushApiService = this.iUnifyPushApiService;
        unifyApiUtils.iUnifySetDoneApiService = this.iUnifySetDoneApiService;
        unifyApiUtils.iUnifyDeleteApiService = this.iUnifyDeleteApiService;
        unifyApiUtils.iUnifySendMsgApiService = this.iUnifySendMsgApiService;
        unifyApiUtils.iUnifyPushLogService = this.iUnifyPushLogService;
        unifyApiUtils.ClientId = this.ClientId;
        unifyApiUtils.todoOperationCode = this.todoOperationCode;
        unifyApiUtils.setOperationCode = this.setOperationCode;
        unifyApiUtils.delOperationCode = this.delOperationCode;
        unifyApiUtils.msgOperationCode = this.msgOperationCode;
        unifyApiUtils.appId = this.appId;
        unifyApiUtils.smkey = this.smkey;
        unifyApiUtils.url = this.url;
        unifyApiUtils.redirectUrl = this.redirectUrl;
        unifyApiUtils.appCode = this.appCode;
    }

    @Value("${unify.ClientId}")
    private  String ClientId;

    @Value("${unify.todoOperationCode}")
    private  String todoOperationCode;

    @Value("${unify.setOperationCode}")
    private  String setOperationCode;

    @Value("${unify.delOperationCode}")
    private  String delOperationCode;

    @Value("${unify.msgOperationCode}")
    private  String msgOperationCode;

    @Value("${unify.appId}")
    private String appId;

    @Value("${unify.smkey}")
    private String smkey;

    @Value("${unify.url}")
    private String url;

    @Value("${unify.redirectUrl}")
    private String redirectUrl;

    @Value("${unify.appCode}")
    private String appCode;

    /**
     *
     * @param exeType 代办任务类型 add 创建代办任务   del  删除代办任务   set  代办变已办
     * @param currentTask 流程中的任务实体
     * @param title 流程标题
     * @param currentOperators 当前办理人（收件人）
     * @param code 流程编码
     * @param creator 创建人id
     * @param creatorName 创建人姓名
     * @param msg 消息内容
     * @return
     */
    public static Boolean push2Unify(String exeType, Task currentTask,String title,List<String> currentOperators,String code,String creator,String creatorName,String businessId, String msg)
    {
        switch (exeType){
            case "add":
                boolean flg = true;
                for (String item:currentOperators) {
                    UnifyTaskVo tvo = task2AddUnifyData(currentTask,title,item,code,creator,businessId);
                    RequestContextHolder.currentRequestAttributes()
                            .setAttribute("ClientId", unifyApiUtils.ClientId, RequestAttributes.SCOPE_REQUEST);
                    RequestContextHolder.currentRequestAttributes()
                            .setAttribute("todoOperationCode", unifyApiUtils.todoOperationCode, RequestAttributes.SCOPE_REQUEST);
                    String res = unifyApiUtils.iUnifyPushApiService.pushTodo(unifyApiUtils.ClientId,unifyApiUtils.todoOperationCode,tvo);
                    log.info("接口推送结果:"+res);
                    log.info("发送创建任务结束=====《");
                    // 日志记录
                    addPushLog(tvo,null,"/Iaw/portal/api/wfms/pushTodo",res,unifyApiUtils.todoOperationCode);

                    Map<String,Object> map = JSONObject.parseObject(res, Map.class);
                    flg = flg && (Boolean) map.get("success");
                }

                return flg;
            case "del":
                UnifyTaskVo tvo = task2DelAndSetUnifyData(currentTask);
                RequestContextHolder.currentRequestAttributes()
                        .setAttribute("ClientId", unifyApiUtils.ClientId, RequestAttributes.SCOPE_REQUEST);
                RequestContextHolder.currentRequestAttributes()
                        .setAttribute("todoOperationCode", unifyApiUtils.delOperationCode, RequestAttributes.SCOPE_REQUEST);
                String dres = unifyApiUtils.iUnifyDeleteApiService.deleteTodo(unifyApiUtils.ClientId,unifyApiUtils.delOperationCode,tvo);
                log.info("接口推送结果:"+dres);
                log.info("发送删除任务结束=====《");
                // 日志记录
                addPushLog(tvo,null,"/Iaw/portal/api/wfms/deleteTodo",dres,unifyApiUtils.delOperationCode);

                Map<String,Object> dmap = JSONObject.parseObject(dres, Map.class);
                return (Boolean) dmap.get("success");
            case "set":
                UnifyTaskVo tvo1 = task2DelAndSetUnifyData(currentTask);
                RequestContextHolder.currentRequestAttributes()
                        .setAttribute("ClientId", unifyApiUtils.ClientId, RequestAttributes.SCOPE_REQUEST);
                RequestContextHolder.currentRequestAttributes()
                        .setAttribute("todoOperationCode", unifyApiUtils.setOperationCode, RequestAttributes.SCOPE_REQUEST);
                String sres = unifyApiUtils.iUnifySetDoneApiService.setDone(unifyApiUtils.ClientId,unifyApiUtils.setOperationCode,tvo1);
                log.info("接口推送结果:"+sres);
                log.info("发送代办变已办任务结束=====《");
                // 日志记录
                addPushLog(tvo1,null,"/Iaw/portal/api/wfms/setDone",sres,unifyApiUtils.setOperationCode);

                Map<String,Object> smap = JSONObject.parseObject(sres, Map.class);
                return (Boolean) smap.get("success");
            case "WXWORK":
                UnifyMsgVo mvo = task2SendMsgData(currentTask,title,currentOperators,creatorName,code,creator,businessId, msg);

                log.info("===========参数==================《");
                log.info(JSONObject.toJSONString(mvo));

                RequestContextHolder.currentRequestAttributes()
                        .setAttribute("ClientId", unifyApiUtils.ClientId, RequestAttributes.SCOPE_REQUEST);
                RequestContextHolder.currentRequestAttributes()
                        .setAttribute("todoOperationCode", unifyApiUtils.msgOperationCode, RequestAttributes.SCOPE_REQUEST);
                String wres = unifyApiUtils.iUnifySendMsgApiService.sendMsg(unifyApiUtils.ClientId,unifyApiUtils.msgOperationCode,mvo);
                log.info("接口推送结果:"+wres);
                log.info("发送企业微信结束=====《");
                // 日志记录
                addPushLog(null,mvo,"/Iaw/portal/api/mms/sendMsg",wres,unifyApiUtils.msgOperationCode);

                Map<String,Object> wmap = JSONObject.parseObject(wres, Map.class);
                return (Boolean) wmap.get("success");
            default:
                return false;
        }
    }

    public static Boolean sendWXWORKTextMsg(String title, List<String> users, String creator, String content){
        UnifyMsgVo mvo = task2SendTextMsgData(title, users, creator, content);

        String wres = unifyApiUtils.iUnifySendMsgApiService.sendMsg(unifyApiUtils.ClientId, unifyApiUtils.msgOperationCode, mvo);

        // 日志记录
        addPushLog(null, mvo,"/Iaw/portal/api/mms/sendMsg", wres,unifyApiUtils.msgOperationCode);

        Map<String,Object> wmap = JSONObject.parseObject(wres, Map.class);
        return (Boolean) wmap.get("success");
    }

    public static void addPushLog(UnifyTaskVo tvo,UnifyMsgVo mvo,String sendApi,String res, String operationCode)
    {
        UnifyPushLog pushlog = new UnifyPushLog();
        pushlog.setId(UUID.randomUUID().toString().replace("-",""));
        pushlog.setSendApi(unifyApiUtils.url+sendApi);

        JSONObject sendPar = new JSONObject();
        JSONObject header = new JSONObject();
        header.put("ClientId",unifyApiUtils.ClientId);
        header.put("OperationCode",operationCode);
        sendPar.put("header",header);
        sendPar.put("bodydata",null == mvo?JSONObject.toJSONString(tvo):JSONObject.toJSONString(mvo));
        pushlog.setSendParam(JSONObject.toJSONString(sendPar));
        pushlog.setSendRes(res);
        Map<String,Object> map = JSONObject.parseObject(res, Map.class);
        pushlog.setSendSuccessFlg((Boolean) map.get("success")?"1":"0");
        pushlog.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        unifyApiUtils.iUnifyPushLogService.insert(pushlog);
    }


    /**
     * 创建代办任务实体转换，将流程总的任务实体转换成统一代办平台的参数
     * @param currentTask
     * @return
     */
    public static UnifyTaskVo task2AddUnifyData(Task currentTask,String title,String currentOperator,String code,String creator,String businessId)
    {
        String nonceStr = SignUtil.generateNonceStr();
        //主体参数--任务
        UnifyTaskVo tvo = new UnifyTaskVo();
        tvo.setNonceStr(nonceStr);
        tvo.setTimestamp(String.valueOf(SignUtil.getCurrentTimestampMs()));
        tvo.setIsUnifiedUser(true);

        //任务详情
        UnifyTaskDetailVo taskDetailVo = new UnifyTaskDetailVo();
        taskDetailVo.setTaskId(currentTask.getId());
        taskDetailVo.setIsUnifiedUser(true);
        taskDetailVo.setType("URL");
        taskDetailVo.setAppId(unifyApiUtils.appId);
        taskDetailVo.setTitle(title);
        taskDetailVo.setContent("您有新的【" + title + "】已经提交至您的待办，请您及时处理。");
//        taskDetailVo.setFlowId("");
//        taskDetailVo.setFlowName("");
        taskDetailVo.setBizId(currentTask.getId());
        taskDetailVo.setCode(code);
//        taskDetailVo.setNodeId("");
//        taskDetailVo.setNodeType("");
        taskDetailVo.setFlowCreator(creator);
//        taskDetailVo.setFlowCreatorName("");
        taskDetailVo.setCurrentHandler(currentOperator);
//        taskDetailVo.setHandleState("INIT");//新发起
        String valiData = null;
        try {
            valiData = AESUtils.encrypt(currentTask.getId()+"##"+unifyApiUtils.appCode);
        } catch (Exception e) {
            log.error("调用加密失败，失败信息：",e.getMessage());
            log.error("调用参数为："+currentTask.getId()+"##"+unifyApiUtils.appCode);
            return null;
        }
        taskDetailVo.setFlowUrl(unifyApiUtils.redirectUrl+"taskId="+currentTask.getId()+"&businessKey="+code+"&businessId="+businessId+"&userId="+currentOperator+"&appCode="+unifyApiUtils.appCode+"&valiData="+ URLEncoder.encode(valiData));
//        taskDetailVo.setThirdArrivalTime(null);//不用传
        taskDetailVo.setRemark(null);//不用传

//        //任务附件
//        UnifyTaskAttachmentVo unifyTaskAttachmentVo = new UnifyTaskAttachmentVo();
//        unifyTaskAttachmentVo.setName("");
//        unifyTaskAttachmentVo.setUrl("");
//        //支持多个附件
//        List<UnifyTaskAttachmentVo> attlist = new ArrayList<>();
//        attlist.add(unifyTaskAttachmentVo);
//
//        taskDetailVo.setAttachments(attlist);
//
//        //历史任务详情参数
//        UnifyHistoryTaskDetailVo historyTaskDetailVo = new UnifyHistoryTaskDetailVo();
//        historyTaskDetailVo.setSerial(1);
//        historyTaskDetailVo.setHandler("");
//        historyTaskDetailVo.setState("");
//        historyTaskDetailVo.setOpinion("");
//
//        List<UnifyHistoryTaskDetailVo> hislist = new ArrayList<>();
//        hislist.add(historyTaskDetailVo);
//
//        taskDetailVo.setHistoryDetails(hislist);

        tvo.setDetails(taskDetailVo);
        tvo.setSign(processSign(tvo,nonceStr));

        return tvo;
    }

    /**
     * 删除代办、代办变已办任务实体转换，将流程总的任务实体转换成统一代办平台的参数
     * @param currentTask
     * @return
     */
    public static UnifyTaskVo task2DelAndSetUnifyData(Task currentTask)
    {

        String nonceStr = SignUtil.generateNonceStr();
        //主体参数--任务
        UnifyTaskVo tvo = new UnifyTaskVo();
        tvo.setIsUnifiedUser(true);
        tvo.setNonceStr(nonceStr);
        tvo.setTimestamp(String.valueOf(SignUtil.getCurrentTimestampMs()));

        //任务详情
        UnifyTaskDetailVo taskDetailVo = new UnifyTaskDetailVo();
        taskDetailVo.setAppId(unifyApiUtils.appId);
        taskDetailVo.setTaskId(currentTask.getId());

        tvo.setDetails(taskDetailVo);
        tvo.setSign(processSignForDelAndSet(tvo,nonceStr));
        return tvo;
    }

    /**
     * 统一消息集成--发送企业微信
     * @param currentTask
     * @return
     */
    public static UnifyMsgVo task2SendMsgData(Task currentTask,String title,List<String> users,String creatorName,String code,String creator,String businessId, String msg)
    {
        String nonceStr = SignUtil.generateNonceStr();
        //主体参数--消息
        UnifyMsgVo tvo = new UnifyMsgVo();

        tvo.setNonceStr(nonceStr);
        tvo.setTimestamp(String.valueOf(SignUtil.getCurrentTimestampMs()));
        tvo.setIsUnifiedUser(true);

        //消息详情
        UnifyMsgDetailVo taskDetailVo = new UnifyMsgDetailVo();
        taskDetailVo.setType("WXWORK");//目前只做企业微信，固定值
        taskDetailVo.setAppId(unifyApiUtils.appId);
        taskDetailVo.setTitle(title);

        JSONObject msgContent = new JSONObject();
        JSONObject contentJson = new JSONObject();
        msgContent.put("wwxMsgType","template_card");
        contentJson.put("card_type","text_notice");

        JSONObject source = new JSONObject();
        source.put("desc","工作提醒");
        source.put("desc_color",1);
        source.put("icon_url","http://123.232.98.26:23000/sdhs-oss-portal-news-lnformation/portal/2023/12/28/b569d5ddc4cf4c7db8a14b00b92771fb/1000-1000.png");
        contentJson.put("source",source);

        JSONObject main_title = new JSONObject();
        main_title.put("title", msg);
        contentJson.put("main_title",main_title);

        JSONArray horizontal_content_list = new JSONArray();
        JSONObject obj1 = new JSONObject();
        obj1.put("keyname","发起人");
        obj1.put("value",creatorName);

        JSONObject obj2 = new JSONObject();
        obj2.put("keyname","创建时间");
        obj2.put("value", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        horizontal_content_list.add(obj1);
        horizontal_content_list.add(obj2);
        contentJson.put("horizontal_content_list",horizontal_content_list);

        JSONArray jump_list = new JSONArray();
        String valiData = null; // 本系统签名
        try {
            valiData = AESUtils.encrypt(currentTask.getId()+"##"+unifyApiUtils.appCode);
        } catch (Exception e) {
            log.error("调用加密失败，失败信息：",e.getMessage());
            log.error("调用参数为："+currentTask.getId()+"##"+unifyApiUtils.appCode);
            return null;
        }

        for (String item:users) {
            JSONObject jpm1 = new JSONObject();
            jpm1.put("type","1");
            jpm1.put("title",title);
            try {

            } catch (Exception e) {
                log.error("调用加密失败，失败信息：",e.getMessage());
                log.error("调用参数为："+currentTask.getId()+"##"+unifyApiUtils.appCode);
                return null;
            }
            jpm1.put("url", unifyApiUtils.redirectUrl+"taskId="+currentTask.getId()+"&businessKey="+code+"&businessId="+businessId+"&userId="+item+"&appCode="+unifyApiUtils.appCode+"&valiData="+URLEncoder.encode(valiData));
            jump_list.add(jpm1);
        }

        contentJson.put("jump_list",jump_list);

        JSONObject card_action = new JSONObject();
        card_action.put("type", 1);
        card_action.put("url", unifyApiUtils.redirectUrl+"taskId="+currentTask.getId()+"&businessKey="+code+"&businessId="+businessId+"&userId="+users.get(0)+"&appCode="+unifyApiUtils.appCode+"&valiData="+URLEncoder.encode(valiData));
        contentJson.put("card_action", card_action);

        msgContent.put("content", contentJson);

        taskDetailVo.setContent(JSONObject.toJSONString(msgContent));
        taskDetailVo.setRemark("");//不用传
        taskDetailVo.setMsgCreator(creator);

        //发送人
        UnifyMsgReceiverVo rvo = new UnifyMsgReceiverVo();
//        rvo.setOrgId(null);//TODO
//        rvo.setGroupId(null);//TODO
//        rvo.setReceiveAddr(null);//TODO
        rvo.setUserId(users);
        taskDetailVo.setReceivers(rvo);

//        //抄送人
//        UnifyMsgCopiedReceiverVo crvo = new UnifyMsgCopiedReceiverVo();
//        crvo.setOrgId(null);//TODO
//        crvo.setGroupId(null);//TODO
//        crvo.setReceiveAddr(null);//TODO
//        crvo.setUserId(null);//TODO
//        taskDetailVo.setCopiedReceivers(crvo);

//        //任务附件
//        UnifyTaskAttachmentVo unifyTaskAttachmentVo = new UnifyTaskAttachmentVo();
//        unifyTaskAttachmentVo.setName("");
//        unifyTaskAttachmentVo.setUrl("");
//        //支持多个附件
//        List<UnifyTaskAttachmentVo> attlist = new ArrayList<>();
//        attlist.add(unifyTaskAttachmentVo);
//        taskDetailVo.setAttList(attlist);

        tvo.setDetails(taskDetailVo);
        tvo.setSign(processSignForMsg(tvo,nonceStr));
        return tvo;
    }

    /**
     * 统一消息集成--发送企业微信
     * @param title
     * @param users
     * @param creator
     * @return
     */
    public static UnifyMsgVo task2SendTextMsgData(String title, List<String> users, String creator, String content)
    {
        String nonceStr = SignUtil.generateNonceStr();
        //主体参数--消息
        UnifyMsgVo tvo = new UnifyMsgVo();

        tvo.setNonceStr(nonceStr);
        tvo.setTimestamp(String.valueOf(SignUtil.getCurrentTimestampMs()));
        tvo.setIsUnifiedUser(true);

        //消息详情
        UnifyMsgDetailVo taskDetailVo = new UnifyMsgDetailVo();
        taskDetailVo.setType("WXWORK");//目前只做企业微信，固定值
        taskDetailVo.setAppId(unifyApiUtils.appId);
        taskDetailVo.setTitle(title);

        JSONObject msgContent = new JSONObject();
        msgContent.put("wwxMsgType","text");
        msgContent.put("content", content);

        taskDetailVo.setContent(JSONObject.toJSONString(msgContent));
        taskDetailVo.setRemark("");//不用传
        taskDetailVo.setMsgCreator(creator);

        //发送人
        UnifyMsgReceiverVo rvo = new UnifyMsgReceiverVo();
        rvo.setUserId(users);
        taskDetailVo.setReceivers(rvo);

        tvo.setDetails(taskDetailVo);
        tvo.setSign(processSignForMsg(tvo,nonceStr));
        return tvo;
    }

    /**
     * 处理统一代办的sign
     * @param tvo
     * @return
     */
    public static String processSign(UnifyTaskVo tvo,String nonceStr)
    {
        JSONObject details = new JSONObject();
        details.put("isUnifiedUser",tvo.getIsUnifiedUser());
        details.put("type",tvo.getDetails().getType());
        details.put("appId",tvo.getDetails().getAppId());
        details.put("bizId",tvo.getDetails().getBizId());
        details.put("code",tvo.getDetails().getCode());
        details.put("title",tvo.getDetails().getTitle());
        details.put("content",tvo.getDetails().getContent());
        details.put("currentHandler",tvo.getDetails().getCurrentHandler());
        details.put("flowCreator",tvo.getDetails().getFlowCreator());
        details.put("taskId",tvo.getDetails().getTaskId());
        details.put("flowUrl",tvo.getDetails().getFlowUrl());
//        details.put("remark",tvo.getDetails().getRemark());

        String sign = null;
        try {
            sign = SignUtil.generateSignature(details, unifyApiUtils.smkey, nonceStr);
        } catch (Exception e) {
            // 根据业务需求处理异常
        }

        return sign;
    }

    public static String processSignForDelAndSet(UnifyTaskVo tvo,String nonceStr)
    {
        JSONObject details = new JSONObject();
        details.put("appId",tvo.getDetails().getAppId());
        details.put("taskId",tvo.getDetails().getTaskId());

        String sign = null;
        try {
            sign = SignUtil.generateSignature(details, unifyApiUtils.smkey, nonceStr);
        } catch (Exception e) {
            // 根据业务需求处理异常
        }

        return sign;
    }

    /**
     * 处理统一消息的sign
     * @param tvo
     * @return
     */
    public static String processSignForMsg(UnifyMsgVo tvo,String nonceStr)
    {
        JSONObject details = new JSONObject();
        details.put("appId",tvo.getDetails().getAppId());
        details.put("type",tvo.getDetails().getType());
        details.put("title",tvo.getDetails().getTitle());

        // 收件人信息
        JSONObject receivers = new JSONObject();
        receivers.put("userId", tvo.getDetails().getReceivers().getUserId());
        details.put("receivers", receivers);

        details.put("content",tvo.getDetails().getContent());
        details.put("msgCreator", tvo.getDetails().getMsgCreator());
        details.put("remark", tvo.getDetails().getRemark());

        String sign = null;
        try {
            sign = SignUtil.generateSignature(details, unifyApiUtils.smkey, nonceStr);
        } catch (Exception e) {
            // 根据业务需求处理异常
        }

        return sign;
    }


//    public static void test(){
//        // 加密用Map
//        // 业务参数
//        JSONObject details = new JSONObject();
//        details.put("appId", "1676495326170099713");
//        details.put("type", "WXWORK");
//        details.put("title", "采购计划制定");
//
//        // 收件人信息
//        JSONObject receivers = new JSONObject();
//        List<String> receiveAddr = new ArrayList<>();
//        receiveAddr.add("20221026185614192-67C3-7E92F90B3");
//        receivers.put("userId", receiveAddr);
//        details.put("receivers", receivers);
//
//        details.put("content", "{\"wwxMsgType\": \"template_card\",\"content\":{\"card_type\":\"text_notice\",\"source\":{\"desc\":\"工作提醒\",\"desc_color\":1,\"icon_url\":\"http://123.232.98.26:23000/sdhs-oss-portal-news-lnformation/portal/2023/12/28/b569d5ddc4cf4c7db8a14b00b92771fb/1000-1000.png\"},\"main_title\":{\"title\":\"李广辉的齐鲁高速测试流程已通过，请查看。\"},\"horizontal_content_list\":[{\"keyname\":\"发起人\",\"value\":\"李广辉\"},{\"keyname\":\"创建时间\",\"value\":\"2025-04-23 15:01:31\"}],\"jump_list\":[{\"type\":1,\"title\":\"点击查看详情。\",\"url\":\"http://www.isdhsg.com/thirdLogin/check?sys=portal&agentId=1000293&method=wwx&urlKey=99e09cc9788c4368ad4972d8d69cc81e\"}],\"card_action\":{\"type\":1,\"url\":\"http://www.isdhsg.com/thirdLogin/check?sys=portal&agentId=1000293&method=wwx&urlKey=99e09cc9788c4368ad4972d8d69cc81e\"}}");
//        details.put("msgCreator", "20230724100806294-245C-8E2806BED");
//        details.put("remark", "测试");
//        // 业务请求参数放入参数验证map
//        String nonceStr = SignUtil.generateNonceStr();
//        String sign = null;
//        try {
//            sign = SignUtil.generateSignature(details, "CKaFsvdscLX6NSzjh3ndIAFEhNuh7cYr", nonceStr);
//        } catch (Exception e) {
//            // 根据业务需求处理异常
//        }
//
//        // 接口请求参数
//        JSONObject requestParams = new JSONObject();
//        requestParams.put("sign", sign);
//        requestParams.put("nonceStr", nonceStr);
//        long currentTimestampMs = SignUtil.getCurrentTimestampMs();
//        requestParams.put("timestamp", String.valueOf(currentTimestampMs));
//        requestParams.put("details", details);
//        requestParams.put("isUnifiedUser", true);
//        System.out.println(requestParams.toJSONString());
//
//    }
}
